package com.example.passport.controller;

import com.example.common.dto.JsonResult;
import com.example.common.dto.ListDto;
import com.example.common.dto.Pagination;
import com.example.common.util.StrUtil;
import com.example.interceptor.UserContext;
import com.example.passport.dto.LoggingDto;
import com.example.passport.dto.UserCreateDto;
import com.example.passport.dto.UserDto;
import com.example.passport.entity.Logging;
import com.example.passport.entity.User;
import com.example.passport.service.LoggingService;
import com.example.passport.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.util.StringUtils;

import javax.annotation.Resource;
import javax.validation.Valid;


@Api(tags = "日志管理")
@RestController
@CrossOrigin
@RequestMapping("/passport/logging")
public class LoggingController {
    @Resource
    public LoggingService loggingService;

    @ApiOperation("获取登录日志")
    @GetMapping("/list")
    public JsonResult<ListDto<LoggingDto>> list(Logging condition, Pagination pagination) {
        User user = UserContext.getUser();
        if("admin".equals(user.getUsername())){
            condition.setUserId(user.getId());
        }
        condition.setTenantId(user.getTenantId());
        return new JsonResult(loggingService.listUser(condition, pagination));
    }

}
